package com.wman;

/**
 * @ProjectName: wman
 * @Package: com.wman
 * @ClassName: Synchronized1Demo
 * @Description: java类作用描述
 * @Author: wman
 * @CreateDate: 2019/12/30 11:29
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/12/30 11:29
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class Synchronized1Demo implements TestDemo {
    private int x, y;

    private synchronized void count(int newValue) {
        x = newValue;
        y = newValue;

        if (x != y) {
            System.out.println("x:" + x + " y:" + y);
        }
    }

    @Override
    public void runTest() {
        new Thread() {
            @Override
            public void run() {
                super.run();
                for (int i = 0; i < 1_000_000_000; i++) {
                    count(i);
                }
            }
        }.start();
        new Thread() {
            @Override
            public void run() {
                super.run();
                for (int i = 0; i < 1_000_000_000; i++) {
                    count(i);
                }
            }
        }.start();
    }
}
